<?php

namespace app\api\model;

use think\Model;

class Order extends Model
{
    protected $type = [
        'address_info'    =>  'json',
    ];


    public static function dataList($where,$page,$num,$field="*",$order="id desc"){
        return self::where($where)->field($field)->order($order)->page($page,$num)->select();
    }

    public static function dataCount($where){
        return self::where($where)->count();
    }

    /***订单信息
     * @param $where array
     * @return json
     */
    public static function dataView($where){
        return self::where($where)->find();
    }


    /*** 新增订单
     * @param $data
     * @return $id
     */
    public static function dataAdd($data){
        return self::create($data);
    }


    /*** 修改订单
     * @param $data
     * @return bool
     */
    public static function dataEdit($where,$data){
        return self::where($where)->update($data);
    }


    /***  批量统计
     * @param $field
     * @param $where
     * @param $group
     * @return mixed
     */
    public static function dataCountList($field,$where,$group){
        return self::field($field)->where($where)->group($group)->select();
    }

    public static function dataCountNum($where,$whereRaw = "1=1"){
        return self::where($where)
            ->whereRaw($whereRaw)
            ->count();
    }
}